<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html>
<html>
<head>
    <title>修改密码</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/layui/css/layui.css">
</head>
<body>

    <form  class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-inline">
                <input type="text" readonly class="layui-input" value="${user.realname}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">账号</label>
            <div class="layui-input-inline">
                <input type="text" readonly class="layui-input" value="${user.username}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">原密码</label>
            <div class="layui-input-inline">
                <input type="text" name="password"  class="layui-input" autocomplete="off" lay-verify="required" lay-reqText="请输入原密码"  >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-inline">
                <input type="text" name="newPassword"  class="layui-input" autocomplete="off" lay-verify="required" lay-reqText="请输入新密码"  >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-inline">
                <input type="text" name="confirmPassword"  class="layui-input" autocomplete="off" lay-verify="required" lay-reqText="请再次输入新密码"  >
            </div>
        </div>
        <div class="layui-form-item" style="margin-top: 30px">
            <button style="width: 140px" type="button" class="layui-btn" id="subBtn" lay-filter="subBtnFilter" lay-submit>确认</button>
            <button style="width: 140px" type="reset" class="layui-btn layui-btn-primary" > 取消</button>
        </div>
    </form>


<script src="${pageContext.request.contextPath}/resources/layui/layui.js"></script>
<script>
    layui.use(['form','jquery','layer'],function () {
        let form = layui.form;
        let $ = layui.jquery;
        let layer = layui.layer;
        let cxt = '${pageContext.request.contextPath}';
        //表单的提交监听事件
        form.on("submit(subBtnFilter)",function (d) {
            let formData = d.field;//获取表单数据
            //对比两次密码是否一致
            let newPassword = formData.newPassword;
            let confirmPassword = formData.confirmPassword;
            if(newPassword != confirmPassword){
                layer.msg("确认密码和新密码不一致,请保持一致");
                return  false;
            }
            //将原始密码和新密码进行提交
            $.post(cxt+"/user.do?service=updatePassword",formData,function (rs) {
                layer.msg(rs.msg);
                if(rs.code != 200){
                    return false;
                }
                //修改成功 去登录页面重新登录
                // window.parent 找到当前子窗口对象的父窗口对象  document  location  history
                //docuemnt.getElementById   --> window.document.getElementById
                //由于是父子页面
                console.log(window);
                window.parent.document.getElementById("logout").click();
            })
            return false;
        })



    });


</script>
</body>
</html>
